package hammersmith.local.valueobjects;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * 
 * Rechnungs-Klasse 
 * TODO: noch nicht eingebunden...
 * @author hammersmith
 *
 */
public class Invoice implements Serializable{

	private static final long serialVersionUID = 2415988870563092797L;
	private long invoiceNumber;
	private String date;
	private int customerID;
	private ShoppingCart cart;
	
	public Invoice(){
		
	}
	
	public Invoice(ArrayList<Customer> customerList, String date, int customerID, ShoppingCart cart){
		this.invoiceNumber = calculateInvoiceNumber(customerList);
		this.date = date;
		this.customerID = customerID;
		this.cart = new ShoppingCart();
		this.cart = cart;
		
	}
	
	public long calculateInvoiceNumber(ArrayList<Customer> customerList){
		
		int high = 99999999;
		int low = 10000000;
		boolean ok = false;
		int id = 0;

		while (!ok) {

			//Zufalls-ID errechnen (1000-9999)
			id = (int) (Math.random() * (high - low) + low);


			//Wenn ID schon vergeben wurde -> false -> negative Meldung 
			//Wenn ID nicht vergeben -> true -> positive Meldung
			for (Customer customer: customerList) {
				for (Invoice invoice : customer.getInvoiceList()) {
					if(invoice.getInvoiceNumber() == id){
						break;
					}
				}	
			}	ok = true;
		}
		return id;
	}

	public long getInvoiceNumber() {
		return invoiceNumber;
	}

	public void setInvoiceNumber(long invoiceNumber) {
		this.invoiceNumber = invoiceNumber;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public int getCustomerID() {
		return customerID;
	}

	public void setCustomerID(int customerID) {
		this.customerID = customerID;
	}

	public ShoppingCart getCart() {
		return cart ;
	}

	public void setCart(ShoppingCart cart) {
		this.cart = cart;
	}
	
}
